package com.vstudy.zx.dao;

import com.vstudy.zx.entity.Message;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MessageDao {

    // 查询会话的最近一次消息
    @Select("select * from tb_message where con_id = #{con_id} order by msg_time desc limit 1;")
    Message selectLastMessage(Long con_id);

    // 查询会话的最近10条记录
    @Select("select * from tb_message where con_id = #{con_id} order by msg_time desc limit #{length};")
    List<Message> selectMessage(@Param("con_id") Long con_id, @Param("length") Integer length);


    @Insert("INSERT INTO tb_message(con_id, from_id, msg_message) VALUES(#{con_id},#{from_id},#{msg_message})")
    int add(@Param("con_id") Long con_id, @Param("msg_message") String msg, @Param("from_id") int from_id);
}
